package androidlab.sprintingsquirrel;

import java.io.IOException;

import org.andengine.audio.music.Music;
import org.andengine.audio.music.MusicFactory;
import org.andengine.audio.sound.Sound;
import org.andengine.audio.sound.SoundFactory;
import org.andengine.engine.Engine;
import org.andengine.engine.camera.BoundCamera;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.opengl.texture.ITexture;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.atlas.bitmap.BuildableBitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.source.IBitmapTextureAtlasSource;
import org.andengine.opengl.texture.atlas.buildable.builder.BlackPawnTextureAtlasBuilder;
import org.andengine.opengl.texture.atlas.buildable.builder.ITextureAtlasBuilder.TextureAtlasBuilderException;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.debug.Debug;

import android.graphics.Color;
import android.util.DisplayMetrics;

public class ResourceManager {

	private static final ResourceManager INSTANCE = new ResourceManager();

	public Engine engine;
	public MainActivity activity;
	public BoundCamera camera;
	public VertexBufferObjectManager vbom;
	public DisplayMetrics metrics;
	public Font font;
	public Font font_cw;
	public Font font_credits_titel;
	public Font font_credits_names;
	public float aspectRatio;

	// Splashscreen
	private BitmapTextureAtlas splashTA;
	public ITextureRegion splashTR;
	
	// Completed Window
	public BuildableBitmapTextureAtlas completedWindowTA;
	public ITextureRegion completedWindowTR;
	public ITiledTextureRegion completedHazelnutsTTR;
	
	// GameOver Window
	public BuildableBitmapTextureAtlas gameOverWindowTA;
	public ITextureRegion gameOverWindowTR;
	public ITextureRegion restartButtonTR;
	
	// Menu
	private BuildableBitmapTextureAtlas menuTA;
	public ITextureRegion playTR, editorTR, homeTR, creditsTR, optionsTR, backgroundTR;
	
	// Game
	private BitmapTextureAtlas controlTA;
	public ITextureRegion baseTR, knobTR;
	
	// Background
	public BitmapTextureAtlas gameBackgroundTA;
	public ITextureRegion gameBackgroundTR;
	
	// Game Texture
	public BuildableBitmapTextureAtlas gameTABlack;
	public BuildableBitmapTextureAtlas gameTASoil;
	public BuildableBitmapTextureAtlas gameTASoilGrass;
	    
	// Game Texture Regions
	//Black Blocks
	public ITextureRegion blockBlackQuadTR;
	public ITextureRegion blockBlackQuad2XTR;
	public ITextureRegion blockBlackQuad3XTR;
	public ITextureRegion blockBlackQuadRectangle45NegTR;
	public ITextureRegion blockBlackQuadRectangle90NegTR;
	public ITextureRegion blockBlackQuadRectangle45TR;
	public ITextureRegion blockBlackQuadRectangle90TR;
	public ITextureRegion blockBlackQuadRectangleHoriTR;
	public ITextureRegion blockBlackQuadRectangleVertiTR;
	public ITextureRegion blockBlackQuadRectangleHori2XTR;
	public ITextureRegion blockBlackQuadRectangleVerti2XTR;
	public ITextureRegion blockBlackTriangle135TR;
	public ITextureRegion blockBlackTriangle180TR;
	public ITextureRegion blockBlackTriangle45TR;
	public ITextureRegion blockBlackTriangle90TR;
	public ITextureRegion blockBlackTriangle2X135TR;
	public ITextureRegion blockBlackTriangle2X180TR;
	public ITextureRegion blockBlackTriangle2X45TR;
	public ITextureRegion blockBlackTriangle2X90TR;
	public ITextureRegion blockBlackTriangle2XVerti135TR;
	public ITextureRegion blockBlackTriangle2XVerti180TR;
	public ITextureRegion blockBlackTriangle2XVerti45TR;
	public ITextureRegion blockBlackTriangle2XVerti90TR;
	//Soil Blocks
	public ITextureRegion blockBodentextur1QuadTR;
	public ITextureRegion blockBodentextur1Quad2XTR;
	public ITextureRegion blockBodentextur1Quad3XTR;
	public ITextureRegion blockBodentextur1QuadRectangle45NegTR;
	public ITextureRegion blockBodentextur1QuadRectangle90NegTR;
	public ITextureRegion blockBodentextur1QuadRectangle45TR;
	public ITextureRegion blockBodentextur1QuadRectangle90TR;
	public ITextureRegion blockBodentextur1QuadRectangleHoriTR;
	public ITextureRegion blockBodentextur1QuadRectangleVertiTR;
	public ITextureRegion blockBodentextur1QuadRectangleHori2XTR;
	public ITextureRegion blockBodentextur1QuadRectangleVerti2XTR;
	public ITextureRegion blockBodentextur1Triangle135TR;
	public ITextureRegion blockBodentextur1Triangle180TR;
	public ITextureRegion blockBodentextur1Triangle45TR;
	public ITextureRegion blockBodentextur1Triangle90TR;
	public ITextureRegion blockBodentextur1Triangle2X135TR;
	public ITextureRegion blockBodentextur1Triangle2X180TR;
	public ITextureRegion blockBodentextur1Triangle2X45TR;
	public ITextureRegion blockBodentextur1Triangle2X90TR;
	public ITextureRegion blockBodentextur1Triangle2XVerti135TR;
	public ITextureRegion blockBodentextur1Triangle2XVerti180TR;
	public ITextureRegion blockBodentextur1Triangle2XVerti45TR;
	public ITextureRegion blockBodentextur1Triangle2XVerti90TR;
	//Soil-Grass Blocks
	public ITextureRegion  blockBodengrasLQuadTR;
	public ITextureRegion  blockBodengrasLQuad2xTR;
	public ITextureRegion  blockBodengrasLQuad3xTR;
	public ITextureRegion  blockBodengrasLRectangleVertiTR;
	public ITextureRegion  blockBodengrasLRectangle2xVertiTR;
	public ITextureRegion  blockBodengrasOQuadTR;
	public ITextureRegion  blockBodengrasOQuad2xTR;
	public ITextureRegion  blockBodengrasOQuad3xTR;
	public ITextureRegion  blockBodengrasORectangle45TR;
	public ITextureRegion  blockBodengrasORectangle45NegTR;
	public ITextureRegion  blockBodengrasORectangle90TR;
	public ITextureRegion  blockBodengrasORectangle90NegTR;
	public ITextureRegion  blockBodengrasORectangleHoriTR;
	public ITextureRegion  blockBodengrasORectangleVertiTR;
	public ITextureRegion  blockBodengrasORectangle2xHoriTR;
	public ITextureRegion  blockBodengrasORectangle2xVertiTR;
	public ITextureRegion  blockBodengrasOTriangle45TR;
	public ITextureRegion  blockBodengrasOTriangle90TR;
	public ITextureRegion  blockBodengrasOTriangle135TR;
	public ITextureRegion  blockBodengrasOTriangle180TR;
	public ITextureRegion  blockBodengrasOTriangle2x45TR;
	public ITextureRegion  blockBodengrasOTriangle2x90TR;
	public ITextureRegion  blockBodengrasOTriangle2x135TR;
	public ITextureRegion  blockBodengrasOTriangle2x180TR;
	public ITextureRegion  blockBodengrasOTriangle2xVerti45TR;
	public ITextureRegion  blockBodengrasOTriangle2xVerti90TR;
	public ITextureRegion  blockBodengrasOTriangle2xVerti135TR;
	public ITextureRegion  blockBodengrasOTriangle2xVerti180TR;
	public ITextureRegion  blockBodengrasOLQuadTR;
	public ITextureRegion  blockBodengrasOLQuad2xTR;
	public ITextureRegion  blockBodengrasOLQuad3xTR;
	public ITextureRegion  blockBodengrasOLRectangle45TR;
	public ITextureRegion  blockBodengrasOLRectangle45NegTR;
	public ITextureRegion  blockBodengrasOLRectangle90NegTR;
	public ITextureRegion  blockBodengrasOLRectangleHoriTR;
	public ITextureRegion  blockBodengrasOLRectangleVertiTR;
	public ITextureRegion  blockBodengrasOLRectangle2xHoriTR;
	public ITextureRegion  blockBodengrasOLRectangle2xVertiTR;
	public ITextureRegion  blockBodengrasOLTriangle45TR;
	public ITextureRegion  blockBodengrasOLTriangle90TR;
	public ITextureRegion  blockBodengrasOLTriangle2x45TR;
	public ITextureRegion  blockBodengrasOLTriangle2x90TR;
	public ITextureRegion  blockBodengrasOLTriangle2xVerti45TR;
	public ITextureRegion  blockBodengrasOLTriangle2xVerti90TR;
	public ITextureRegion  blockBodengrasORQuadTR;
	public ITextureRegion  blockBodengrasORQuad2xTR;
	public ITextureRegion  blockBodengrasORQuad3xTR;
	public ITextureRegion  blockBodengrasORRectangle45TR;
	public ITextureRegion  blockBodengrasORRectangle45NegTR;
	public ITextureRegion  blockBodengrasORRectangle90TR;
	public ITextureRegion  blockBodengrasORRectangleHoriTR;
	public ITextureRegion  blockBodengrasORRectangleVertiTR;
	public ITextureRegion  blockBodengrasORRectangle2xHoriTR;
	public ITextureRegion  blockBodengrasORRectangle2xVertiTR;
	public ITextureRegion  blockBodengrasORTriangle135TR;
	public ITextureRegion  blockBodengrasORTriangle180TR;
	public ITextureRegion  blockBodengrasORTriangle2x135TR;
	public ITextureRegion  blockBodengrasORTriangle2x180TR;
	public ITextureRegion  blockBodengrasORTriangle2xVerti135TR;
	public ITextureRegion  blockBodengrasORTriangle2xVerti180TR;
	public ITextureRegion  blockBodengrasRQuadTR;
	public ITextureRegion  blockBodengrasRQuad2xTR;
	public ITextureRegion  blockBodengrasRQuad3xTR;
	public ITextureRegion  blockBodengrasRRectangleVertiTR;
	public ITextureRegion  blockBodengrasRRectangle2xVertiTR;
	//Items
	public ITextureRegion hazelnut_TR;
	//Logical entities
	public ITiledTextureRegion playerTR;
	public ITiledTextureRegion monsterTR;
	public ITextureRegion endTR;
	
	// Musik
	public Sound jumpSound;
	public Sound eatSound;
	public Sound levelCompleteSound;
	public Sound gameOverSound;
	
	// Editor Texture
	public BuildableBitmapTextureAtlas editorTA;
	
	// Editor Texture Regions
	public ITextureRegion gitterTR;
	public ITextureRegion hammerTR;
	public ITiledTextureRegion deleteTTR;

	// Sharing Texture
	public BuildableBitmapTextureAtlas sharingTA;
	
	// Sharing Texture Region
	public ITextureRegion suchenTR;
	public ITextureRegion wartenTR;
	public ITextureRegion sendenTR;
	
	//Loading
	private BuildableBitmapTextureAtlas loadingTA;
	public ITextureRegion loadingTR;
	
	public Music music;
	
	private String level;
	private int x;
	private int y;

	public void loadMenuResources() {
		loadMenuGraphics();
		loadMenuAudio();
		loadMenuFonts();
	}

	public void loadGameResources(String level) {
		this.level = level;
		loadGameGraphics();
		loadCompletedWindowGraphics();
		loadGameOverGraphics();
		loadGameFonts();
		loadGameAudio();
	}
	
	public void loadEditorResources(String level, int x, int y) {
		this.level = level;
		this.x = x;
		this.y = y;
		loadEditorGraphics();
		loadGameGraphics();
	}
	
	public void loadLoadingResources() {
		loadLoadingGraphics();
	}
	
	public void loadSharingResources() {
		loadSharingGraphics();
	}

	private void loadMenuGraphics() {
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("graphics/");
		menuTA = new BuildableBitmapTextureAtlas(
				activity.getTextureManager(), 2048, 2048, TextureOptions.BILINEAR);
		playTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(menuTA,
				activity, "button_play.png");
		editorTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
				menuTA, activity, "button_editor.png");
		creditsTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
				menuTA, activity, "button_credits.png");
		optionsTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
				menuTA, activity, "button_options.png");
		homeTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(menuTA,
				activity, "button_home_small.png");
		backgroundTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(menuTA, activity, "background_menu.png");
		
		try {
			menuTA.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(
					0, 1, 0));
			menuTA.load();
		} catch (final TextureAtlasBuilderException e) {
			
		}
	}
	
	private void loadLoadingGraphics() {
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("graphics/");
		loadingTA = new BuildableBitmapTextureAtlas(activity.getTextureManager(), 512, 256, TextureOptions.BILINEAR);
		loadingTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(loadingTA, activity, "loading.png");
		
		try {
			loadingTA.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(
					0, 1, 0));
			loadingTA.load();
		} catch (final TextureAtlasBuilderException e) {
			
		}
	}
	
	private void loadCompletedWindowGraphics() {
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("graphics/");
		completedWindowTA = new BuildableBitmapTextureAtlas(activity.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
		completedWindowTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(completedWindowTA, activity, "level_geschafft_v2.png");
		completedHazelnutsTTR = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(completedWindowTA, activity, "hazelnut_complete.png", 2, 1);
		
		try {
			completedWindowTA.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(
					0, 1, 0));
			completedWindowTA.load();
		} catch (final TextureAtlasBuilderException e) {
			
		}
	}
	

	private void loadGameOverGraphics() {
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("graphics/");
		gameOverWindowTA = new BuildableBitmapTextureAtlas(activity.getTextureManager(), 1536, 1536, TextureOptions.BILINEAR);
		gameOverWindowTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameOverWindowTA, activity, "level_verloren.png");
		restartButtonTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameOverWindowTA, activity, "restart_button.png");
		
		try {
			gameOverWindowTA.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(
					0, 1, 0));
			gameOverWindowTA.load();
		} catch (final TextureAtlasBuilderException e) {
			
		}
	}

	private void loadMenuAudio() {

	}
	
	private void loadMenuFonts() {
	    FontFactory.setAssetBasePath("fonts/");
	    final ITexture mainFontTexture = new BitmapTextureAtlas(activity.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
	    final ITexture completedWindowFontTexture = new BitmapTextureAtlas(activity.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
	    final ITexture creditsFontTextureTitel = new BitmapTextureAtlas(activity.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
	    final ITexture creditsFontTextureNames = new BitmapTextureAtlas(activity.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);

	    font = FontFactory.createStrokeFromAsset(activity.getFontManager(), mainFontTexture, activity.getAssets(), "font.ttf", 150, true, Color.WHITE, 2, Color.BLACK);
	    font_cw = FontFactory.createStrokeFromAsset(activity.getFontManager(), completedWindowFontTexture, activity.getAssets(), "toontime_cw.ttf", 150, true, Color.BLACK, 2, Color.BLACK);
	    font_credits_titel = FontFactory.createStrokeFromAsset(activity.getFontManager(), creditsFontTextureTitel, activity.getAssets(), "akashi_credits_titel.ttf", 150, true, Color.WHITE, 2, Color.WHITE);
	    font_credits_names = FontFactory.createStrokeFromAsset(activity.getFontManager(), creditsFontTextureNames, activity.getAssets(), "justOldFashion_credits_names.ttf", 150, true, Color.WHITE, 2, Color.WHITE);
	    font.load();
	    font_cw.load();
	    font_credits_titel.load();
	    font_credits_names.load();
	}

	private void loadGameGraphics() {
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("graphics/");
		controlTA = new BitmapTextureAtlas(activity.getTextureManager(),
				512, 256, TextureOptions.BILINEAR);
		baseTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
				controlTA, activity, "control_base.png", 0, 0);
		knobTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
				controlTA, activity, "control_knob.png", 256, 0);
		controlTA.load();
		
		gameBackgroundTA = new BitmapTextureAtlas(activity.getTextureManager(), 2048, 512, TextureOptions.BILINEAR);
		gameBackgroundTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameBackgroundTA, activity, "wald.png", 0, 0);
		gameBackgroundTA.load();
		
		gameTABlack = new BuildableBitmapTextureAtlas(activity.getTextureManager(), 2048, 2048, TextureOptions.BILINEAR);
		gameTASoil = new BuildableBitmapTextureAtlas(activity.getTextureManager(), 2048, 2048, TextureOptions.BILINEAR);
		gameTASoilGrass = new BuildableBitmapTextureAtlas(activity.getTextureManager(), 2048, 2048, TextureOptions.BILINEAR);
		
	    //Black Blocks
	    blockBlackQuadTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_black_quad.png");
	    blockBlackQuad2XTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_black_quad2x.png");
	    blockBlackQuad3XTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_black_quad3x.png");
	    blockBlackQuadRectangle45NegTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_black_rectangle_-45deg.png");
	    blockBlackQuadRectangle90NegTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_black_rectangle_-90deg.png");
	    blockBlackQuadRectangle45TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_black_rectangle_45deg.png");
	    blockBlackQuadRectangle90TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_black_rectangle_90deg.png");
	    blockBlackQuadRectangleHoriTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_black_rectangle_hori.png");
	    blockBlackQuadRectangleVertiTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_black_rectangle_verti.png");
	    blockBlackQuadRectangleHori2XTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_black_rectangle2x_hori.png");
	    blockBlackQuadRectangleVerti2XTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_black_rectangle2x_verti.png");
	    blockBlackTriangle135TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_triangle_135deg.png");
	    blockBlackTriangle180TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_triangle_180deg.png");
	    blockBlackTriangle45TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_triangle_45deg.png");
	    blockBlackTriangle90TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_triangle_90deg.png");
	    blockBlackTriangle2X135TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_triangle2x_135deg.png");
	    blockBlackTriangle2X180TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_triangle2x_180deg.png");
	    blockBlackTriangle2X45TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_triangle2x_45deg.png");
	    blockBlackTriangle2X90TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_triangle2x_90deg.png");
	    blockBlackTriangle2XVerti135TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_triangle2x_verti_135deg.png");
	    blockBlackTriangle2XVerti180TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_triangle2x_verti_180deg.png");
	    blockBlackTriangle2XVerti45TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_triangle2x_verti_45deg.png");
	    blockBlackTriangle2XVerti90TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "block_triangle2x_verti_90deg.png");
	    //Soil Blocks
	    blockBodentextur1QuadTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_quad.png");
	    blockBodentextur1Quad2XTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_quad2x.png");
	    blockBodentextur1Quad3XTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_quad3x.png");
	    blockBodentextur1QuadRectangle45NegTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_rectangle_-45deg.png");
	    blockBodentextur1QuadRectangle90NegTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_rectangle_-90deg.png");
	    blockBodentextur1QuadRectangle45TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_rectangle_45deg.png");
	    blockBodentextur1QuadRectangle90TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_rectangle_90deg.png");
	    blockBodentextur1QuadRectangleHoriTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_rectangle_hori.png");
	    blockBodentextur1QuadRectangleVertiTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_rectangle_verti.png");
	    blockBodentextur1QuadRectangleHori2XTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_rectangle2x_hori.png");
	    blockBodentextur1QuadRectangleVerti2XTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_rectangle2x_verti.png");
	    blockBodentextur1Triangle135TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_triangle_135deg.png");
	    blockBodentextur1Triangle180TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_triangle_180deg.png");
	    blockBodentextur1Triangle45TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_triangle_45deg.png");
	    blockBodentextur1Triangle90TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_triangle_90deg.png");
	    blockBodentextur1Triangle2X135TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_triangle2x_135deg.png");
	    blockBodentextur1Triangle2X180TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_triangle2x_180deg.png");
	    blockBodentextur1Triangle2X45TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_triangle2x_45deg.png");
	    blockBodentextur1Triangle2X90TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_triangle2x_90deg.png");
	    blockBodentextur1Triangle2XVerti135TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_triangle2x_verti_135deg.png");
	    blockBodentextur1Triangle2XVerti180TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_triangle2x_verti_180deg.png");
	    blockBodentextur1Triangle2XVerti45TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_triangle2x_verti_45deg.png");
	    blockBodentextur1Triangle2XVerti90TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoil, activity, "block_bodentextur1_triangle2x_verti_90deg.png");
	    //Soil-Grass Blocks
	    blockBodengrasLQuadTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_L_quad.png");
		blockBodengrasLQuad2xTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_L_quad2x.png");
		blockBodengrasLQuad3xTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_L_quad3x.png");
		blockBodengrasLRectangleVertiTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_L_rectangle_verti.png");
		blockBodengrasLRectangle2xVertiTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_L_rectangle2x_verti.png");
		blockBodengrasOQuadTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_quad.png");
		blockBodengrasOQuad2xTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_quad2x.png");
		blockBodengrasOQuad3xTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_quad3x.png");
		blockBodengrasORectangle45TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_rectangle_45deg.png");
		blockBodengrasORectangle45NegTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_rectangle_-45deg.png");
		blockBodengrasORectangle90TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_rectangle_90deg.png");
		blockBodengrasORectangle90NegTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_rectangle_-90deg.png");
		blockBodengrasORectangleHoriTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_rectangle_hori.png");
		blockBodengrasORectangleVertiTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_rectangle_verti.png");
		blockBodengrasORectangle2xHoriTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_rectangle2x_hori.png");
		blockBodengrasORectangle2xVertiTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_rectangle2x_verti.png");
		blockBodengrasOTriangle45TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_triangle_45deg.png");
		blockBodengrasOTriangle90TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_triangle_90deg.png");
		blockBodengrasOTriangle135TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_triangle_135deg.png");
		blockBodengrasOTriangle180TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_triangle_180deg.png");
		blockBodengrasOTriangle2x45TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_triangle2x_45deg.png");
		blockBodengrasOTriangle2x90TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_triangle2x_90deg.png");
		blockBodengrasOTriangle2x135TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_triangle2x_135deg.png");
		blockBodengrasOTriangle2x180TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_triangle2x_180deg.png");
		blockBodengrasOTriangle2xVerti45TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_triangle2x_verti_45deg.png");
		blockBodengrasOTriangle2xVerti90TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_triangle2x_verti_90deg.png");
		blockBodengrasOTriangle2xVerti135TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_triangle2x_verti_135deg.png");
		blockBodengrasOTriangle2xVerti180TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_O_triangle2x_verti_180deg.png");
		blockBodengrasOLQuadTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OL_quad.png");
		blockBodengrasOLQuad2xTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OL_quad2x.png");
		blockBodengrasOLQuad3xTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OL_quad3x.png");
		blockBodengrasOLRectangle45TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OL_rectangle_45deg.png");
		blockBodengrasOLRectangle45NegTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OL_rectangle_-45deg.png");
		blockBodengrasOLRectangle90NegTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OL_rectangle_-90deg.png");
		blockBodengrasOLRectangleHoriTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OL_rectangle_hori.png");
		blockBodengrasOLRectangleVertiTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OL_rectangle_verti.png");
		blockBodengrasOLRectangle2xHoriTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OL_rectangle2x_hori.png");
		blockBodengrasOLRectangle2xVertiTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OL_rectangle2x_verti.png");
		blockBodengrasOLTriangle45TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OL_triangle_45deg.png");
		blockBodengrasOLTriangle90TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OL_triangle_90deg.png");
		blockBodengrasOLTriangle2x45TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OL_triangle2x_45deg.png");
		blockBodengrasOLTriangle2x90TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OL_triangle2x_90deg.png");
		blockBodengrasOLTriangle2xVerti45TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OL_triangle2x_verti_45deg.png");
		blockBodengrasOLTriangle2xVerti90TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OL_triangle2x_verti_90deg.png");
		blockBodengrasORQuadTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OR_quad.png");
		blockBodengrasORQuad2xTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OR_quad2x.png");
		blockBodengrasORQuad3xTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OR_quad3x.png");
		blockBodengrasORRectangle45TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OR_rectangle_45deg.png");
		blockBodengrasORRectangle45NegTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OR_rectangle_-45deg.png");
		blockBodengrasORRectangle90TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OR_rectangle_90deg.png");
		blockBodengrasORRectangleHoriTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OR_rectangle_hori.png");
		blockBodengrasORRectangleVertiTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OR_rectangle_verti.png");
		blockBodengrasORRectangle2xHoriTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OR_rectangle2x_hori.png");
		blockBodengrasORRectangle2xVertiTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OR_rectangle2x_verti.png");
		blockBodengrasORTriangle135TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OR_triangle_135deg.png");
		blockBodengrasORTriangle180TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OR_triangle_180deg.png");
		blockBodengrasORTriangle2x135TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OR_triangle2x_135deg.png");
		blockBodengrasORTriangle2x180TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OR_triangle2x_180deg.png");
		blockBodengrasORTriangle2xVerti135TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OR_triangle2x_verti_135deg.png");
		blockBodengrasORTriangle2xVerti180TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_OR_triangle2x_verti_180deg.png");
		blockBodengrasRQuadTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_R_quad.png");
		blockBodengrasRQuad2xTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_R_quad2x.png");
		blockBodengrasRQuad3xTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_R_quad3x.png");
		blockBodengrasRRectangleVertiTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_R_rectangle_verti.png");
		blockBodengrasRRectangle2xVertiTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTASoilGrass, activity, "block_bodengras_R_rectangle2x_verti.png");
	    //Items
	    hazelnut_TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "hazelnut.png");
	    //Logical entities
	    playerTR = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(gameTABlack, activity, "player.png", 4, 2);
	    monsterTR = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(gameTABlack, activity, "monster.png", 4, 2);
	    endTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(gameTABlack, activity, "baum.png");
	    
	    try {
	        this.gameTABlack.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 0));
	        this.gameTABlack.load();
	        this.gameTASoil.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 0));
	        this.gameTASoil.load();
	        this.gameTASoilGrass.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 0));
	        this.gameTASoilGrass.load();
	    } catch (final TextureAtlasBuilderException e) {
	        Debug.e(e);
	    }
	}

	private void loadGameFonts() {

	}

	private void loadGameAudio() {
		SoundFactory.setAssetBasePath("sounds/");
		
		try {
			jumpSound = SoundFactory.createSoundFromAsset(activity.getSoundManager(), activity, "Jump.mp3");
			eatSound = SoundFactory.createSoundFromAsset(activity.getSoundManager(), activity, "eating.mp3");
			levelCompleteSound = SoundFactory.createSoundFromAsset(activity.getSoundManager(), activity, "ff_levelcomplete.mp3");
			gameOverSound = SoundFactory.createSoundFromAsset(activity.getSoundManager(), activity, "sonic_gameover.mp3");
			jumpSound.setVolume(0.2f);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private void loadEditorGraphics() {
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("graphics/");
		editorTA = new BuildableBitmapTextureAtlas(activity.getTextureManager(), 512, 512, TextureOptions.BILINEAR);
		gitterTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(editorTA, activity, "gitter.png");
		hammerTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(editorTA, activity, "hammer.png");
		deleteTTR = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(editorTA, activity, "delete_tiled.png", 2, 1);
		
		try {
	        this.editorTA.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 0));
	        this.editorTA.load();
	    } catch (final TextureAtlasBuilderException e) {
	        Debug.e(e);
	    }
	}
	
	private void loadSharingGraphics() {
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("graphics/");
		sharingTA = new BuildableBitmapTextureAtlas(activity.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
		suchenTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(sharingTA, activity, "lupe.png");
		wartenTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(sharingTA, activity, "sanduhr.png");
		sendenTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(sharingTA, activity, "brief.png");
		
		try {
	        this.sharingTA.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 0));
	        this.sharingTA.load();
	    } catch (final TextureAtlasBuilderException e) {
	        Debug.e(e);
	    }
	}

	public void loadSplashScreen() {
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("graphics/");
		splashTA = new BitmapTextureAtlas(this.activity.getTextureManager(),
				256, 512);
		splashTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(
				splashTA, this.activity, "splash.png", 0, 0);
		splashTA.load();

		MusicFactory.setAssetBasePath("music/");
		try {
			music = MusicFactory.createMusicFromAsset(engine.getMusicManager(),
					activity, "GiorgioByMoroder-DaftPunk.mid");
			music.setVolume(0.8f);
			music.setLooping(true);
		} catch (IOException e) {
			e.printStackTrace();
		}

		if (music != null && !music.isPlaying()) {
			music.play();
		}
	}

	public void unloadSplashScreen() {
		splashTA.unload();
		splashTR = null;
	}
	
	public void unloadLoadingTextures() {
		loadingTA.unload();
	}
	
	public void loadLoadingTextures() {
		loadingTA.load();
	}
	
	public void unloadMenuTextures() {
		menuTA.unload();
	}
	    
	public void loadMenuTextures() {
		menuTA.load();
	}
	
	public void unloadGameTextures() {
		controlTA.unload();
		baseTR = null;
		knobTR = null;
		gameBackgroundTA.unload();
		gameTABlack.unload();
		gameTASoil.unload();
		gameTASoilGrass.unload();
	}
	
	public void unloadEditorTextures() {
		editorTA.unload();
	}
	
	public void unloadSharingTextures() {
		sharingTA.unload();
	}
	
	public String getLevel() {
		return level;
	}
	
	public int getX() {
		return x;
	}
	
	public int getY() {
		return y;
	}

	public static void initManager(Engine engine, MainActivity activity,
			BoundCamera camera, VertexBufferObjectManager vbom, DisplayMetrics metrics, float aspectRatio) {
		getInstance().engine = engine;
		getInstance().activity = activity;
		getInstance().camera = camera;
		getInstance().vbom = vbom;
		getInstance().metrics = metrics;
		getInstance().aspectRatio = aspectRatio;
	}

	public static ResourceManager getInstance() {
		return INSTANCE;
	}
}
